{
 "cells": [
  {
   "cell_type": "code",
   "id": "76ac0e42092c0d50",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-17T02:18:36.121989Z",
     "start_time": "2025-05-17T02:18:29.392054Z"
    }
   },
   "source": [
    "import unsloth\n",
    "import torch\n",
    "import torch.nn as nn\n",
    "import torch.nn.functional as F\n",
    "import math\n",
    "from modelscope import AutoTokenizer, AutoModelForCausalLM, snapshot_download\n",
    "from unsloth import FastLanguageModel\n",
    "# 设置pip国内镜像源（推荐清华源）\n",
    "import os"
   ],
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "🦥 Unsloth: Will patch your computer to enable 2x faster free finetuning.\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\51165\\.conda\\envs\\e12\\Lib\\site-packages\\tqdm\\auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
      "  from .autonotebook import tqdm as notebook_tqdm\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "🦥 Unsloth Zoo will now patch everything to make training faster!\n"
     ]
    }
   ],
   "execution_count": 1
  },
  {
   "cell_type": "code",
   "id": "4252d7a6ab0128a9",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-17T02:18:36.224317Z",
     "start_time": "2025-05-17T02:18:36.221261Z"
    }
   },
   "source": [
    "max_seq_length = 2048\n",
    "dtype = None\n",
    "load_in_4bit = True"
   ],
   "outputs": [],
   "execution_count": 2
  },
  {
   "cell_type": "code",
   "id": "f195cd2d4033b116",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-17T02:18:37.061117Z",
     "start_time": "2025-05-17T02:18:36.234708Z"
    }
   },
   "source": [
    "model_name = \"unsloth/Qwen3-8B\"\n",
    "model_dir = snapshot_download(model_name)"
   ],
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Downloading Model from https://www.modelscope.cn to directory: C:\\Users\\51165\\.cache\\modelscope\\hub\\models\\unsloth\\Qwen3-8B\n"
     ]
    }
   ],
   "execution_count": 3
  },
  {
   "cell_type": "code",
   "id": "46416b76f189aebd",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-17T02:18:52.929708Z",
     "start_time": "2025-05-17T02:18:37.066928Z"
    }
   },
   "source": [
    "model, tokenizer = FastLanguageModel.from_pretrained(\n",
    "    model_dir,\n",
    "    max_seq_length=max_seq_length,\n",
    "    dtype=dtype,\n",
    "    load_in_4bit=load_in_4bit\n",
    ")"
   ],
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "==((====))==  Unsloth 2025.4.7: Fast Qwen3 patching. Transformers: 4.51.3.\n",
      "   \\\\   /|    NVIDIA GeForce RTX 2080 Ti. Num GPUs = 1. Max memory: 11.0 GB. Platform: Windows.\n",
      "O^O/ \\_/ \\    Torch: 2.6.0+cu126. CUDA: 7.5. CUDA Toolkit: 12.6. Triton: 3.2.0\n",
      "\\        /    Bfloat16 = FALSE. FA [Xformers = 0.0.29.post3. FA2 = False]\n",
      " \"-____-\"     Free license: http://github.com/unslothai/unsloth\n",
      "Unsloth: Fast downloading is enabled - ignore downloading bars which are red colored!\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\51165\\.conda\\envs\\e12\\Lib\\site-packages\\unsloth_zoo\\gradient_checkpointing.py:330: UserWarning: expandable_segments not supported on this platform (Triggered internally at C:\\actions-runner\\_work\\pytorch\\pytorch\\pytorch\\c10/cuda/CUDAAllocatorConfig.h:28.)\n",
      "  GPU_BUFFERS = tuple([torch.empty(2*256*2048, dtype = dtype, device = f\"cuda:{i}\") for i in range(n_gpus)])\n",
      "Loading checkpoint shards: 100%|██████████| 4/4 [00:10<00:00,  2.65s/it]\n"
     ]
    }
   ],
   "execution_count": 4
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-17T02:18:52.953205Z",
     "start_time": "2025-05-17T02:18:52.947711Z"
    }
   },
   "cell_type": "code",
   "source": "model",
   "id": "54a8f345b340d7b6",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Qwen3ForCausalLM(\n",
       "  (model): Qwen3Model(\n",
       "    (embed_tokens): Embedding(151936, 4096, padding_idx=151654)\n",
       "    (layers): ModuleList(\n",
       "      (0-35): 36 x Qwen3DecoderLayer(\n",
       "        (self_attn): Qwen3Attention(\n",
       "          (q_proj): Linear4bit(in_features=4096, out_features=4096, bias=False)\n",
       "          (k_proj): Linear4bit(in_features=4096, out_features=1024, bias=False)\n",
       "          (v_proj): Linear4bit(in_features=4096, out_features=1024, bias=False)\n",
       "          (o_proj): Linear4bit(in_features=4096, out_features=4096, bias=False)\n",
       "          (q_norm): Qwen3RMSNorm((128,), eps=1e-06)\n",
       "          (k_norm): Qwen3RMSNorm((128,), eps=1e-06)\n",
       "          (rotary_emb): LlamaRotaryEmbedding()\n",
       "        )\n",
       "        (mlp): Qwen3MLP(\n",
       "          (gate_proj): Linear4bit(in_features=4096, out_features=12288, bias=False)\n",
       "          (up_proj): Linear4bit(in_features=4096, out_features=12288, bias=False)\n",
       "          (down_proj): Linear4bit(in_features=12288, out_features=4096, bias=False)\n",
       "          (act_fn): SiLU()\n",
       "        )\n",
       "        (input_layernorm): Qwen3RMSNorm((4096,), eps=1e-06)\n",
       "        (post_attention_layernorm): Qwen3RMSNorm((4096,), eps=1e-06)\n",
       "      )\n",
       "    )\n",
       "    (norm): Qwen3RMSNorm((4096,), eps=1e-06)\n",
       "    (rotary_emb): LlamaRotaryEmbedding()\n",
       "  )\n",
       "  (lm_head): Linear(in_features=4096, out_features=151936, bias=False)\n",
       ")"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 5
  },
  {
   "cell_type": "code",
   "id": "f8a5f33231d3ac37",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-17T02:18:52.980998Z",
     "start_time": "2025-05-17T02:18:52.977994Z"
    }
   },
   "source": [
    "prompt_style = \"\"\"以下是描述任务的指令，以及提供进一步上下文的输入。\n",
    "请写出一个适当完成请求的回答。\n",
    "在回答之前，请仔细思考问题，并创建一个逻辑连贯的思考过程，以确保回答准确无误。\n",
    "\n",
    "### 指令：\n",
    "你是一位精通卜卦、星象和运势预测的算命大师。\n",
    "请回答以下算命问题。\n",
    "\n",
    "### 问题：\n",
    "{}\n",
    "\n",
    "### 回答：\n",
    "<think>{}\"\"\"\n",
    "# 定义提示风格的字符串模板，用于格式化问题\n",
    "\n",
    "question = \"1992年闰四月初九巳时生人，女，想了解健康运势\"\n",
    "# 定义具体的算命问题"
   ],
   "outputs": [],
   "execution_count": 6
  },
  {
   "cell_type": "code",
   "id": "d613f7181ad5621f",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-17T02:18:53.007080Z",
     "start_time": "2025-05-17T02:18:53.004125Z"
    }
   },
   "source": [
    "# FastLanguageModel.for_inference(model)\n",
    "# # 准备模型以进行推理\n",
    "#\n",
    "# inputs = tokenizer([prompt_style.format(question, \"\")], return_tensors=\"pt\").to(\"cuda\")\n",
    "# # 使用 tokenizer 对格式化后的问题进行编码，并移动到 GPU\n",
    "#\n",
    "# outputs = model.generate(\n",
    "#     input_ids=inputs.input_ids,\n",
    "#     attention_mask=inputs.attention_mask,\n",
    "#     max_new_tokens=1200,\n",
    "#     use_cache=True,\n",
    "# )\n",
    "# # 使用模型生成回答\n",
    "#\n",
    "# response = tokenizer.batch_decode(outputs)\n",
    "# # 解码模型生成的输出为可读文本\n",
    "#\n",
    "# print(response[0])"
   ],
   "outputs": [],
   "execution_count": 7
  },
  {
   "cell_type": "code",
   "id": "d40fefdeaf4282f5",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-17T02:18:53.033995Z",
     "start_time": "2025-05-17T02:18:53.030990Z"
    }
   },
   "source": [
    "# 定义一个用于格式化提示的多行字符串模板\n",
    "train_prompt_style = \"\"\"以下是描述任务的指令，以及提供进一步上下文的输入。\n",
    "请写出一个适当完成请求的回答。\n",
    "在回答之前，请仔细思考问题，并创建一个逻辑连贯的思考过程，以确保回答准确无误。\n",
    "\n",
    "### 指令：\n",
    "你是一位精通八字算命、 紫微斗数、 风水、易经卦象、塔罗牌占卜、星象、面相手相和运势预测等方面的算命大师。\n",
    "请回答以下算命问题。\n",
    "\n",
    "### 问题：\n",
    "{}\n",
    "\n",
    "### 回答：\n",
    "<思考>\n",
    "{}\n",
    "</思考>\n",
    "{}\"\"\""
   ],
   "outputs": [],
   "execution_count": 8
  },
  {
   "cell_type": "code",
   "id": "ef4fb4c886605e8e",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-17T02:18:53.061242Z",
     "start_time": "2025-05-17T02:18:53.058238Z"
    }
   },
   "source": [
    "EOS_TOKEN = tokenizer.eos_token  # 必须添加结束标记"
   ],
   "outputs": [],
   "execution_count": 9
  },
  {
   "cell_type": "code",
   "id": "dd3ce6d57a9b5126",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-17T02:19:01.350704Z",
     "start_time": "2025-05-17T02:18:53.083726Z"
    }
   },
   "source": [
    "from modelscope.msdatasets import MsDataset\n",
    "dataset_name = 'AI-ModelScope/fortune-telling'\n",
    "dataset = MsDataset.load(dataset_name, trust_remote_code=True, subset_name=\"default\", split=\"train\")"
   ],
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2025-05-17 10:18:53,112 - modelscope - WARNING - Use trust_remote_code=True. Will invoke codes from fortune-telling. Please make sure that you can trust the external codes.\n",
      "2025-05-17 10:18:53,654 - modelscope - WARNING - Use trust_remote_code=True. Will invoke codes from AI-ModelScope/fortune-telling. Please make sure that you can trust the external codes.\n",
      "2025-05-17 10:18:53,654 - modelscope - WARNING - Use trust_remote_code=True. Will invoke codes from AI-ModelScope/fortune-telling. Please make sure that you can trust the external codes.\n",
      "2025-05-17 10:18:53,654 - modelscope - WARNING - Use trust_remote_code=True. Will invoke codes from AI-ModelScope/fortune-telling. Please make sure that you can trust the external codes.\n"
     ]
    }
   ],
   "execution_count": 10
  },
  {
   "cell_type": "code",
   "id": "b826760f72fd4b04",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-17T02:19:01.371436Z",
     "start_time": "2025-05-17T02:19:01.368282Z"
    }
   },
   "source": [
    "len(dataset)"
   ],
   "outputs": [
    {
     "data": {
      "text/plain": [
       "207"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 11
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-17T02:19:01.394589Z",
     "start_time": "2025-05-17T02:19:01.391301Z"
    }
   },
   "cell_type": "code",
   "source": "dataset",
   "id": "968723300ceb1214",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Dataset({\n",
       "    features: ['Question', 'Response', 'Complex_CoT'],\n",
       "    num_rows: 207\n",
       "})"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 12
  },
  {
   "cell_type": "code",
   "id": "f8cf71f1c0b6f0d0",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-17T02:19:01.445866Z",
     "start_time": "2025-05-17T02:19:01.438630Z"
    }
   },
   "source": [
    "# 定义一个函数，用于格式化数据集中的每条记录\n",
    "def formatting_prompts_func(examples):\n",
    "    # 从数据集中提取问题、复杂思考过程和回答\n",
    "    inputs = examples[\"Question\"]\n",
    "    cots = examples[\"Complex_CoT\"]\n",
    "    outputs = examples[\"Response\"]\n",
    "    texts = []  # 用于存储格式化后的文本\n",
    "    # 遍历每个问题、思考过程和回答，进行格式化\n",
    "    for input, cot, output in zip(inputs, cots, outputs):\n",
    "        # 使用字符串模板插入数据，并加上结束标记\n",
    "        text = train_prompt_style.format(input, cot, output) + EOS_TOKEN\n",
    "        texts.append(text)  # 将格式化后的文本添加到列表中\n",
    "    return {\n",
    "        \"text\": texts,  # 返回包含所有格式化文本的字典\n",
    "    }\n",
    "\n",
    "dataset = dataset.map(formatting_prompts_func, batched = True)\n",
    "dataset[\"text\"][0]"
   ],
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'以下是描述任务的指令，以及提供进一步上下文的输入。\\n请写出一个适当完成请求的回答。\\n在回答之前，请仔细思考问题，并创建一个逻辑连贯的思考过程，以确保回答准确无误。\\n\\n### 指令：\\n你是一位精通八字算命、 紫微斗数、 风水、易经卦象、塔罗牌占卜、星象、面相手相和运势预测等方面的算命大师。\\n请回答以下算命问题。\\n\\n### 问题：\\n新房装修,大门对着电梯好不好?要如何化解?\\n\\n### 回答：\\n<思考>\\n好的，用户问的是新房装修时大门对着电梯好不好，以及如何化解。首先，我需要回忆一下风水学中关于大门和电梯的相关知识。电梯在风水中属于动气比较强的地方，因为电梯频繁开合，会带来不稳定的气流，也就是所谓的“煞气”。大门是住宅的纳气口，如果正对电梯，可能会让这些不稳定的气流直接冲进家里，影响居住者的健康和财运。\\n\\n接下来，我需要确认用户的具体情况。比如，大门和电梯的距离有多远？是否正对还是稍微偏一点？不过用户没有提供这些细节，所以只能给出一般性的建议。化解的方法通常有几种：屏风或玄关、门帘、五帝钱、植物、八卦镜等。需要逐一解释这些方法的原理和使用方式，同时提醒用户要根据实际情况选择，必要时咨询专业风水师。\\n\\n另外，还要注意语气要亲切，避免使用过于专业的术语，让用户容易理解。同时，要强调这些是传统方法，效果因人而异，保持客观中立。最后，可以建议用户如果情况复杂，最好请专业人士实地查看，这样更稳妥。\\n\\n</思考>\\n根据传统风水学的观点，大门正对电梯易形成\"开口煞\"，电梯频繁升降会扰乱家宅气场。建议化解方案：\\n\\n1. 玄关阻隔法\\n在入门处设置L型屏风或文化砖玄关墙，高度以1.8米为宜，既保持采光又形成缓冲带\\n\\n2. 五行通关法\\n门槛石下埋设五帝钱+白玉葫芦，建议选丙申年铸造的真品古币，配合门楣悬挂九宫八卦镜\\n\\n3. 光影化解术\\n安装磨砂玻璃内推门，门框镶嵌黄铜门槛，每日辰时用海盐净化门廊区域\\n\\n4. 现代科技方案\\n入户区安装智能感应灯带，设置循环播放的流水声效，运用声光电技术平衡磁场\\n\\n需注意电梯井方位与家主命卦的关系，建议提供具体户型平面图进行吉凶方位测算。当代建筑中可采用半透明艺术隔断结合空气净化系统，既符合科学原理又兼顾传统智慧。<|im_end|>'"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 13
  },
  {
   "cell_type": "code",
   "id": "93e79c10358fbd98",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-17T02:19:03.599983Z",
     "start_time": "2025-05-17T02:19:01.473815Z"
    }
   },
   "source": [
    "FastLanguageModel.for_training(model)\n",
    "\n",
    "model = FastLanguageModel.get_peft_model(\n",
    "    model,  # 传入已经加载好的预训练模型\n",
    "    r = 16,  # 设置 LoRA 的秩，决定添加的可训练参数数量\n",
    "    target_modules = [\"q_proj\", \"k_proj\", \"v_proj\", \"o_proj\",  # 指定模型中需要微调的关键模块\n",
    "                      \"gate_proj\", \"up_proj\", \"down_proj\"],\n",
    "    lora_alpha = 16,  # 设置 LoRA 的超参数，影响可训练参数的训练方式\n",
    "    lora_dropout = 0,  # 设置防止过拟合的参数，这里设置为 0 表示不丢弃任何参数\n",
    "    bias = \"none\",    # 设置是否添加偏置项，这里设置为 \"none\" 表示不添加\n",
    "    use_gradient_checkpointing = \"unsloth\",  # 使用优化技术节省显存并支持更大的批量大小\n",
    "    random_state = 3407,  # 设置随机种子，确保每次运行代码时模型的初始化方式相同\n",
    "    use_rslora = False,  # 设置是否使用 Rank Stabilized LoRA 技术，这里设置为 False 表示不使用\n",
    "    loftq_config = None,  # 设置是否使用 LoftQ 技术，这里设置为 None 表示不使用\n",
    ")"
   ],
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Unsloth 2025.4.7 patched 36 layers with 36 QKV layers, 36 O layers and 36 MLP layers.\n"
     ]
    }
   ],
   "execution_count": 14
  },
  {
   "cell_type": "code",
   "id": "7b5f57cfda77e0b2",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-17T02:19:03.971969Z",
     "start_time": "2025-05-17T02:19:03.641354Z"
    }
   },
   "source": [
    "from trl import SFTTrainer, SFTConfig  # 导入 SFTTrainer，用于监督式微调\n",
    "from transformers import TrainingArguments  # 导入 TrainingArguments，用于设置训练参数\n",
    "from unsloth import is_bfloat16_supported  # 导入函数，检查是否支持 bfloat16 数据格式\n",
    "\n",
    "trainer = SFTTrainer(  # 创建一个 SFTTrainer 实例\n",
    "    model=model,  # 传入要微调的模型\n",
    "    tokenizer=tokenizer,  # 传入 tokenizer，用于处理文本数据\n",
    "    train_dataset=dataset,  # 传入训练数据集\n",
    "    dataset_text_field=\"text\",  # 指定数据集中文本字段的名称\n",
    "    max_seq_length=max_seq_length,  # 设置最大序列长度\n",
    "    dataset_num_proc=1,  # 设置数据处理的并行进程数\n",
    "    packing=False,  # 是否启用打包功能（这里设置为 False，打包可以让训练更快，但可能影响效果）\n",
    "    args=TrainingArguments(  # 定义训练参数\n",
    "        per_device_train_batch_size=6,  # 每个设备（如 GPU）上的批量大小\n",
    "        gradient_accumulation_steps=2,  # 梯度累积步数，用于模拟大批次训练\n",
    "        warmup_steps=5,  # 预热步数，训练开始时学习率逐渐增加的步数\n",
    "        # max_steps=75,  # 最大训练步数\n",
    "        num_train_epochs=1,\n",
    "        learning_rate=2e-4,  # 学习率，模型学习新知识的速度\n",
    "        fp16=not is_bfloat16_supported(),  # 是否使用 fp16 格式加速训练（如果环境不支持 bfloat16）\n",
    "        bf16=is_bfloat16_supported(),  # 是否使用 bfloat16 格式加速训练（如果环境支持）\n",
    "        logging_steps=1,  # 每隔多少步记录一次训练日志\n",
    "        optim=\"adamw_8bit\",  # 使用的优化器，用于调整模型参数\n",
    "        weight_decay=0.01,  # 权重衰减，防止模型过拟合\n",
    "        lr_scheduler_type=\"linear\",  # 学习率调度器类型，控制学习率的变化方式\n",
    "        seed=3407,  # 随机种子，确保训练结果可复现\n",
    "        output_dir=\"outputs\",  # 训练结果保存的目录\n",
    "        report_to=\"none\",  # 是否将训练结果报告到外部工具（如 WandB），这里设置为不报告pip\n",
    "    ),\n",
    ")"
   ],
   "outputs": [],
   "execution_count": 15
  },
  {
   "cell_type": "code",
   "id": "2e3ceeb63033a1ff",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-17T02:24:11.903602Z",
     "start_time": "2025-05-17T02:19:03.995450Z"
    }
   },
   "source": [
    "%%time\n",
    "import time\n",
    "start = time.time()\n",
    "trainer_stats = trainer.train()\n",
    "print(time.time()-start)"
   ],
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "==((====))==  Unsloth - 2x faster free finetuning | Num GPUs used = 1\n",
      "   \\\\   /|    Num examples = 207 | Num Epochs = 1 | Total steps = 17\n",
      "O^O/ \\_/ \\    Batch size per device = 6 | Gradient accumulation steps = 2\n",
      "\\        /    Data Parallel GPUs = 1 | Total batch size (6 x 2 x 1) = 12\n",
      " \"-____-\"     Trainable parameters = 43,646,976/8,000,000,000 (0.55% trained)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Unsloth: Will smartly offload gradients to save VRAM!\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ],
      "text/html": [
       "\n",
       "    <div>\n",
       "      \n",
       "      <progress value='17' max='17' style='width:300px; height:20px; vertical-align: middle;'></progress>\n",
       "      [17/17 04:49, Epoch 0/1]\n",
       "    </div>\n",
       "    <table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       " <tr style=\"text-align: left;\">\n",
       "      <th>Step</th>\n",
       "      <th>Training Loss</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>1</td>\n",
       "      <td>1.813400</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2</td>\n",
       "      <td>1.816300</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3</td>\n",
       "      <td>1.930600</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4</td>\n",
       "      <td>1.849600</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>5</td>\n",
       "      <td>1.692600</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>6</td>\n",
       "      <td>1.593400</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>7</td>\n",
       "      <td>1.583800</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>8</td>\n",
       "      <td>1.548400</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>9</td>\n",
       "      <td>1.585700</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>10</td>\n",
       "      <td>1.510900</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>11</td>\n",
       "      <td>1.487300</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>12</td>\n",
       "      <td>1.402700</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>13</td>\n",
       "      <td>1.490100</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>14</td>\n",
       "      <td>1.452400</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>15</td>\n",
       "      <td>1.219400</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>16</td>\n",
       "      <td>1.290500</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>17</td>\n",
       "      <td>1.376300</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table><p>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "307.90406346321106\n",
      "CPU times: total: 1min 28s\n",
      "Wall time: 5min 7s\n"
     ]
    }
   ],
   "execution_count": 16
  },
  {
   "cell_type": "code",
   "id": "c5596494ea0593e0",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-17T02:24:11.983350Z",
     "start_time": "2025-05-17T02:24:11.980504Z"
    }
   },
   "source": [
    "print(question) # 打印前面的问题"
   ],
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1992年闰四月初九巳时生人，女，想了解健康运势\n"
     ]
    }
   ],
   "execution_count": 17
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-17T02:24:12.088475Z",
     "start_time": "2025-05-17T02:24:12.061055Z"
    }
   },
   "cell_type": "code",
   "source": "torch.cuda.empty_cache()",
   "id": "c9cc5044f4160d95",
   "outputs": [],
   "execution_count": 18
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-17T02:24:12.140893Z",
     "start_time": "2025-05-17T02:24:12.138893Z"
    }
   },
   "cell_type": "code",
   "source": "",
   "id": "d14913e6874de6b4",
   "outputs": [],
   "execution_count": null
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "3.11.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
